'use strict';
//
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	//获取数据库对象
	const db = uniCloud.database();
	//获取表的对象
	const tb = db.collection("apply");
	//根据类型进行不同操作
	switch (event.type) {
		//添加一条数据
		case "addApply": {
			let{user_id,company_id,job_id,
			company_name,job_name,time
			}=event;
			let data= tb.add({
				user_id:user_id,
				company_id:company_id,
				job_id:job_id,
				company_name:company_name,
				job_name:job_name,
				state:0,
				time:time
			})
			return {status:200,data:data}
		};
		/*
		 使用多次查询查询用户岗位申请信息
		*/
		case "showApply": {
			let {user_id}=event;
			//查询所有的申请
			let allList=await tb.where({
				user_id:user_id
			}).get()
			//查询被查看的申请
			let beSeenList=await tb.where({
				user_id:user_id,
				state:1
			}).get()
			//查询通过初筛的申请
			let PassPrimaryScreeningList=await tb.where({
				user_id:user_id,
				state:2
			}).get()
			//查询面试的申请
			let interviewList=await tb.where({
				user_id:user_id,
				state:3
			}).get()
			//查询不合适的申请
			let inappropriateList=await tb.where({
				user_id:user_id,
				state:4
			}).get()
			return {status:200,allList:allList,
			beSeenList:beSeenList,
			PassPrimaryScreeningList:PassPrimaryScreeningList,
			interviewList:interviewList,
			inappropriateList:inappropriateList
			}
		};
	}
};